package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.AnalysisManageRightRoleMenuRel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2018-11-26 15:06:00
 */
@Repository
public class AnalysisManageRightRoleMenuRelDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(AnalysisManageRightRoleMenuRelDao.class);

    public AnalysisManageRightRoleMenuRel insert(final AnalysisManageRightRoleMenuRel analysisManageRightRoleMenuRel) {
        insert("AnalysisManageRightRoleMenuRel.insert", analysisManageRightRoleMenuRel);
        return analysisManageRightRoleMenuRel;
    }

    public Boolean updateInfoById(final AnalysisManageRightRoleMenuRel analysisManageRightRoleMenuRel) {
        return update("AnalysisManageRightRoleMenuRel.updateInfoById", analysisManageRightRoleMenuRel) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("AnalysisManageRightRoleMenuRel.updateInfoByQuery", query) > 0;
    }

    public AnalysisManageRightRoleMenuRel selectById(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return queryForObject("AnalysisManageRightRoleMenuRel.selectById", query);
    }

    public List<AnalysisManageRightRoleMenuRel> selectByQuery(final Query query) {
        return queryForList("AnalysisManageRightRoleMenuRel.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("AnalysisManageRightRoleMenuRel.countByQuery", query);
    }

    public Boolean deleteById(final Integer id) {
        AnalysisManageRightRoleMenuRel analysisManageRightRoleMenuRel = new AnalysisManageRightRoleMenuRel();
        analysisManageRightRoleMenuRel.setDeleteFlag(1);
        analysisManageRightRoleMenuRel.setId(id);

        return update("AnalysisManageRightRoleMenuRel.updateInfoById", analysisManageRightRoleMenuRel) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("AnalysisManageRightRoleMenuRel.deleteById", query) > 0;
    }

    //物理删除，role_id批量删除
    public Boolean deletePhysicalByRoleId(final Integer roleId) {
        Query query = Query.noPage();
        query.put("roleId", roleId);
        return delete("AnalysisManageRightRoleMenuRel.deleteForBatch", query) > 0;
    }

    public void insertForBatch(final List<AnalysisManageRightRoleMenuRel> list) {
        insert("AnalysisManageRightRoleMenuRel.insertForBatch", list);
    }
}